296C - Greg and Array - CodeForces Solution


data structures dp implementation *1400

Please click on ads to support us..

C++ Code:

/*
    Author : Krish Italiya
    Date : 20-04-2023
*/
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long 
#define ll long long int
#define vll vector<ll>
#define UB(v,x) distance(v.begin(),upper_bound(all(v),(x)))
#define LB(v,x) distance(v.begin(),lower_bound(all(v),(x)))
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define mpll map<ll, ll>
#define ld long double
// #define float double
#define f(i, x, n) for (int i = x; i < n; i++)
#define rf(i, x, n) for (int i = x; i >= n; i--)
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a)   (ll)a.size()
#define pi (3.141592653589)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e) max(a,max(b,max(c,max(d,e))))
#define min5(a,b,c,d,e) min(a,min(b,min(c,min(d,e))))
bool isprime(ll number){if (number <= 1)return false;if (number == 2)return true;if (number % 2 == 0) return false;int boundary = (int)floor(sqrt(number));for (int i = 3; i <= boundary; i += 2)if (number % i == 0)return false;return true;}
ll gcd(ll x,ll y){if(y==0)return x;return gcd(y,x%y);}
ll exponentiation(long long a, long long b, long long c) {
      long long ans = 1;
      for(int i = 1;i <= b;i++) {
          ans *= a;                             //multiplying a, b times.
          ans %= c;
      }
  return ans;
}

#define slow ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
// #define mod  1000000007
#define mod 10000000007
#define endl '\n'

void solve(){
  ll n,m,k;
  cin>>n>>m>>k;
  vll v(n+2);
  f(i,1,n+1)cin>>v[i];
  vector<vector<ll>> ops;
  f(i,0,m){
    ll l,r,d;
    cin>>l>>r>>d;
    ops.push_back({l,r,d});
  }
  ll qs[m+2] = {0};
  f(i,0,k){
    ll x,y;
    cin>>x>>y;
    qs[x] += 1;
    qs[y+1] -= 1;
  }
  f(i,1,m+1){
    qs[i] += qs[i-1];
  }
  // f(i,1,m+1){
  //   cout<<qs[i]<<" ";
  // }cout<<endl;
  ll add[n+2] = {0};
  f(i,1,m+1){
    ll l = ops[i-1][0];
    ll r = ops[i-1][1];
    ll d = ops[i-1][2];

    // cout<<l<<" "<<r<<" "<<d<<endl;
    add[l] += qs[i]*d;
    add[r+1] -= qs[i]*d;
  }


  f(i,1,n+2){
    add[i] += add[i-1];
  }

  f(i,1,n+1){
    v[i] += add[i];
  }

  f(i,1,n+1){
    cout<<v[i]<<" ";
  }cout<<endl;

  


}     





ll j=1;
int main()
{
    slow;
    ll tt = 1;
    // cin>>tt;    
    while (tt--)
    {
        // cout<<"Case "<<j<<": "<<endl;
        // cout<<"Scenario #"<<j<<":"<<endl;
        solve();
        j++;
    }
    return 0;
}   


Comments

Submit
0 Comments
More Questions

Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game